mkdir("step");
mkdir("ball");
if ($txt == "/test") {
$num1 = rand(1, 30);
$num2 = rand(30, 60);
$javob = $num1 + $num2;
$xato1 = $javob - rand(1, 10);
$xato2 = $javob + rand(1, 10);
$answers = array("$xato1", "$xato2", "$javob");
shuffle($answers);
$true_id = array_keys($answers, "$javob")[0];
$bot->request('SendPoll', [
'chat_id' => $cid,
'question' => $num1 . " + " . $num2 . " = ??",
'allows_multiple_answers' => true,
'type' => 'quiz',
'explanation' => "To'g'ri javob " . $javob . " edi", //malumot berish
'open_period' => 10, //javob berish vaqti
'correct_option_id' => $true_id, //0 dan boshlanadi tog'ri javob varyanti
'is_anonymous' => false, //anonim bolishi
'options' => json_encode($answers),
]);
file_put_contents("step/$cid.txt", $true_id);
file_put_contents("ball/$cid.txt", "0");
}
if (isset($update->poll_answer)) {
$answer_id = $update->poll_answer->option_ids[0];
$user = $update->poll_answer->user->id;
$true_id = file_get_contents("step/$user.txt");
$ball = file_get_contents("ball/$user.txt");
if ($answer_id == $true_id) {
$num1 = rand(1, 30);
$num2 = rand(30, 60);
$javob = $num1 + $num2;
$xato1 = $javob - rand(1, 10);
$xato2 = $javob + rand(1, 10);
$answers = array("$xato1", "$xato2", "$javob");
shuffle($answers);
$true_id = array_keys($answers, "$javob")[0];
file_put_contents("step/$user.txt", $true_id);
$bot->request('SendPoll', [
'chat_id' => $user,
'question' => $num1 . " + " . $num2 . " = ??",
'allows_multiple_answers' => true,
'type' => 'quiz',
'explanation' => "To'g'ri javob " . $javob . " edi", //malumot berish
'open_period' => 10, //javob berish vaqti
'correct_option_id' => $true_id, //0 dan boshlanadi tog'ri javob varyanti
'is_anonymous' => false, //anonim bolishi
'options' => json_encode($answers),
]);
file_put_contents("ball/$user.txt", $ball + 10);
} else {
$bot->request('sendmessage', [
'chat_id' => $user,
'text' => "Siz $ball to'pladingiz va o'yinni yakunladingiz, Yangi test uchun /test"
]);
unlink("ball/$user.txt");
unlink("step/$user.txt");
}
}
Kimgadur kerak bolib qolar)
<?php
include 'bot.php';
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Bog'lanishda xatolik yuz berdi: " . $conn->connect_error);
}
switch ($txt) {
case 'Tasodifiy videolar':
// Tasodifiy 10 ta video
$sql = "SELECT * FROM videos ORDER BY RAND() LIMIT 10";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$i = 1;
$key = [];
while ($row = $result->fetch_assoc()) {
$video_id = $row['video_id'];
$key[] = ["text" => $i, "callback_data" => $video_id];
$i++;
}
$key = array_chunk($key, 5);
$key[] = [
['text' => '⬅️', 'callback_data' => 'previous'],
['text' => '❌️', 'callback_data' => 'close'],
['text' => '➡️', 'callback_data' => 'next']
];
$sql = "SELECT * FROM videos ORDER BY RAND() LIMIT 1";
$f = $conn->query($sql);
$result = $f->fetch_assoc();
$video = $result['video_url'];
$caption = $result['video_caption'];
$reply_markup = json_encode([
'inline_keyboard' => $key,
]);
$bot->sendVideo($cid, $video, $caption, $reply_markup);
}
break;
}
?>
Kimgadur kerak bo'lib qolar :)
<?php
function monthFunction($berilganSana) {
$bugun = new DateTime();
$berilganSana = new DateTime($berilganSana);
$farq = $bugun->diff($berilganSana);
$oylar = $farq->y * 12 + $farq->m;
$natija = array();
$oylarMassivi = array(
"Yanvar", "Fevral", "Mart", "Aprel", "May", "Iyun",
"Iyul", "Avgust", "Sentyabr", "Oktyabr", "Noyabr", "Dekabr"
);
$yillar = array();
for ($i = 0; $i < $oylar; $i++) {
$oy = $berilganSana->modify('+1 month')->format('F');
$yil = date('Y', strtotime($berilganSana->format('Y-m-d')));
$yillar[$yil][] = $oy;
}
$natija["ok"] = true;
$natija["result"]["month_count"] = $oylar;
$natija["result"]["month"] = $yillar;
echo json_encode($natija,JSON_PRETTY_PRINT);
}
monthFunction('2023-01-01');
Result:
{
"ok": true,
"result": {
"month_count": 10,
"month": {
"2023": [
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November"
]
}
}
}
Kim yozganini bilib turib "men yozganman" deydiganlar sog' bo'lasilar😄
Please open Telegram to view this post
VIEW IN TELEGRAM
<?php
function bot($method, $datas = [])
{
$url = "https://api.telegram.org/bot" . API_KEY . "/" . $method;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
$res = curl_exec($ch);
if (curl_error($ch)) {
var_dump(curl_error($ch));
} else {
return json_decode($res);
}
}
function approveChatJoinRequest($channel_id, $user_id)
{
bot('approveChatJoinRequest', [
'chat_id' => $channel_id,
'user_id' => $user_id,
]);
}
function getChatMember($channel_id, $user_id)
{
$status = bot('getChatMember', [
'chat_id' => $channel_id,
'user_id' => $user_id,
]);
$status = $status->result->status;
return $status;
}
$update = json_decode(file_get_contents('php://input'));
if (isset($update)) {
if (isset($update->message)) {
$message = $update->message;
$text = $message->text;
$cid = $message->chat->id;
$mid = $message->message_id;
} elseif (isset($update->callback_query)) {
$data = $update->callback_query->data;
$mid = $update->callback_query->message->message_id;
$cid = $update->callback_query->message->chat->id;
} elseif (isset($update->chat_join_request)) {
$chname = $update->chat_join_request->chat->title;
$chuid = $update->chat_join_request->from->id;
$chid = $update->chat_join_request->chat->id;
$join = $update->chat_join_request;
}
}
if (isset($join)) {
$select = $db->query("SELECT * FROM channels WHERE main_channel=$chid AND secondary_channel IS NOT NULL");
if ($select->num_rows == 1) {
$f = $select->fetch_assoc();
$s_channel = $f['secondary_channel'];
if (in_array(getChatMember($s_channel, $chuid), ['member', 'administrator', 'creator'])) {
approveChatJoinRequest($chid, $chuid);
bot('sendMessage', [
'chat_id' => $chuid,
'text' => "Sizning so'rovingiz tasdiqlandi",
'parse_mode' => "html"
]);
} else {
file_put_contents("cache/" . $chuid . ".txt", $f['id']);
bot('sendMessage', [
'chat_id' => $chuid,
'text' => "Sizning so'rovingiz tasdiqlanishi uchun $s_channel ga obuna bo'ling, siznign so'rovingiz keyin tasdiqlanadi",
'parse_mode' => "html",
'reply_markup' => json_encode([
'inline_keyboard' => [
[['text' => "✅ Obuna bo'ldim", 'callback_data' => "ok"]]
]
])
]);
}
} else {
approveChatJoinRequest($chid, $chuid);
bot('sendMessage', [
'chat_id' => $chuid,
'text' => "Sizning so'rovingiz tasdiqlandi",
'parse_mode' => "html"
]);
}
}
if ($data == "ok") {
$id = file_get_contents("cache/" . $cid . ".txt");
$select = $db->query("SELECT * FROM channels WHERE id=$id");
$f = $select->fetch_assoc();
$s_channel = $f['secondary_channel'];
if (in_array(getChatMember($s_channel, $cid), ['member', 'administrator', 'creator'])) {
$channel_id = $f['main_channel'];
approveChatJoinRequest($channel_id, $cid);
bot('sendMessage', [
'chat_id' => $cid,
'text' => "Sizning so'rovingiz tasdiqlandi",
'parse_mode' => "html"
]);
}
}
CREATE TABLE channels (
id INT AUTO_INCREMENT PRIMARY KEY,
main_channel VARCHAR(255) NOT NULL,
secondary_channel VARCHAR(255)
);
❗️Webhookda: allowed_updates=["message","edited_channel_post", "callback_query","my_chat_member","chat_member","chat_join_request"]
This media is not supported in your browser
VIEW IN TELEGRAM
Happy brithday to me :)
Davay obunachila pul yig‘ib sovg‘a olila nx😂
9860120140779519
9860120140779519
Please open Telegram to view this post
VIEW IN TELEGRAM
#Maslaxat
Siz biron bir lohiya boshlayotganda avval aynan nimalar qilinishi kerakligini bilib oling, hoh u telegram bot bo'lsin, hoh sayt. Loyiha struktur ko'rinishini tuzing. Malumotlar bazasini korinishini tuzing. Keyin qolgan malumotlarni toplashni boshlashingiz mumkin. Hamma malumotlar to'liq bo'lgach sekin kod yozishni boshlashingiz mumkin.
Siz biron bir lohiya boshlayotganda avval aynan nimalar qilinishi kerakligini bilib oling, hoh u telegram bot bo'lsin, hoh sayt. Loyiha struktur ko'rinishini tuzing. Malumotlar bazasini korinishini tuzing. Keyin qolgan malumotlarni toplashni boshlashingiz mumkin. Hamma malumotlar to'liq bo'lgach sekin kod yozishni boshlashingiz mumkin.
dbdiagram.io
A Free Database Designer for Developers and Analysts
Quick and simple free tool to help you draw your database relationship diagrams and flow quickly using just keyboard
Forwarded from Foydali botlar
Kanalga kelgan yangi "qo'shilish so'rovlar"ini qabul qilish
Kanaldagi eski "qo'shilish so'rovlar"ini qabul qilish
Please open Telegram to view this post
VIEW IN TELEGRAM